function previewImg(targetObj) {
	var previewId = targetObj.id;
	var preview = document.getElementById(previewId + "_preview");
	var ua = window.navigator.userAgent;
	if (ua.indexOf("MSIE") > -1) {
		targetObj.select();
		try {
			var src = document.selection.createRange().text;
			var ie_preview_error = document.getElementById("ie_preview_error_"
					+ previewId);

			if (ie_preview_error) {
				preview.removeChild(ie_preview_error);
			}

			$("#" + previewId + "_preview").html("");
			var img = document.getElementById(previewId + "_preview");

			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
					+ src + "', sizingMethod='scale')";

			var hiddenPreview = document.getElementById("hiddenP");
			hiddenPreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
					+ src + "', sizingMethod='image')";
			$("#big_preview").html("");
			$("#big_preview").css("filter", img.style.filter);
			$("#hiddenP").css("width", "1px");
			$("#hiddenP").css("height", "1px");
			$("#" + previewId + "_size").html(
					$("#hiddenP").css("width") + " x "
							+ $("#hiddenP").css("height"));

		} catch (e) {
			if (!document.getElementById("ie_preview_error_" + previewId)) {
				var info = document.createElement("<p>");
				info.id = "ie_preview_error_" + previewId;
				info.innerHTML = "a";
				preview.insertBefore(info, null);
			}
		}
	} else {
		var files = targetObj.files;
		for ( var i = 0; i < files.length; i++) {

			var file = files[i];

			var imageType = /image.*/;
			if (!file.type.match(imageType))
				continue;

			var prevImg = document.getElementById("prev_" + previewId);
			if (prevImg) {
				preview.removeChild(prevImg);
			}

			var img = document.createElement("img");
			img.id = "prev_" + previewId;
			img.classList.add("obj");
			img.file = file;
			img.style.width = '90px';
			img.style.height = '90px';

			$("#" + previewId + "_preview").html("");
			preview.appendChild(img);

			$("#big_preview").html(
					"<img id='bigImg' style='width:300px;height:328px;' />");

			if (window.FileReader) {
				var reader = new FileReader();
				reader.onloadend = (function(aImg) {
					return function(e) {
						aImg.src = e.target.result;
						$("#bigImg").attr("src", e.target.result);
						var imageForSize = new Image();
						imageForSize.onload = function() {
							$("#" + previewId + "_size").html(
									this.width + " x " + this.height);
						};
						imageForSize.src = e.target.result;
					};
				})(img);
				reader.readAsDataURL(file);
			} else {
				if (!document.getElementById("sfr_preview_error_" + previewId)) {
					var info = document.createElement("p");
					info.id = "sfr_preview_error_" + previewId;
					info.innerHTML = "not supported FileReader";
					preview.insertBefore(info, null);
				}
			}
		}
	}
}
function mousePreview(num) {
	var ua = window.navigator.userAgent;
	if (ua.indexOf("MSIE") > -1) {
		$("#big_preview").css("filter",
				$("#img" + num + "_preview").css("filter"));
	} else {
		$("#bigImg").attr("src", $("#prev_img" + num).attr("src"));
	}
}

function fileClear(obj) {
	var imgId = obj.id;
	var ua = window.navigator.userAgent;
	if (ua.indexOf("MSIE") > -1) {
		var thisObj = $("#" + imgId);
		thisObj.select();
		document.selection.clear();
	} else {
		$("#" + imgId).val("");
	}
}

function serviceAllCtr(chk) {
	var serviceChks = $("input[id=serviceChk]");
	if (chk.checked) {
		for ( var i = 0; i < serviceChks.length; i++) {
			serviceChks[i].checked = true;
		}
	} else {
		for ( var i = 0; i < serviceChks.length; i++) {
			serviceChks[i].checked = false;
		}
	}
	checkGgong();
}

function checkServiceAll() {
	var serviceAllChk = $("#serviceAllChk");
	var serviceChks = $("input[id=serviceChk]");
	var checkedNum = 0;
	for ( var i = 0; i < serviceChks.length; i++) {
		if (serviceChks[i].checked) {
			checkedNum++;
		}
	}
	if (checkedNum == 4) {
		serviceAllChk[0].checked = true;
	} else {
		serviceAllChk[0].checked = false;
	}
	checkGgong();
}

function checkGgong() {
	var ggongChk = $("input[name=g_ggong]");
	if (ggongChk[0].checked) {
		$("input[name=offerggong]").attr("disabled", false);
	} else {
		$("input[name=offerggong]").attr("disabled", true);
	}
}

function checkInput() {
	var chks = $("input[id=serviceChk]");
	var result = 0;
	for ( var i = 0; i < chks.length; i++ ) {
		if ( chks[i].checked ) {
			result++;
		}
	}
	if( $("input[name=name]").val() == "" ) {
		alert("게임명을 입력하세요.");
		return false;
	} else if ( $("textarea[name=info]").val() == "" ) {
		alert("게임 상세 설명을 입력하세요.");
		return false;
	} else if ( result <= 0 ) {
		alert( "1개 이상 체크하세요." );
		return false;
	} else if ( $("input[name=g_ggong]").is(":checked") && $("input[name=offerggong]").val() == "" ) {
		alert( "꽁 제공량을 입력하세요." );
		return false;
	} else if ( $("textarea[name=m_detail]").val() == "" ) {
		alert( "미션 가이드를 입력하세요." );
		return false;
	} else if ( $("#img0").val() == "" ) {
		alert( "메인 이미지파일을 등록하세요." );
		return false;
	} else if ( $("#img1").val() == "" ) {
		alert( "첫번째 상세이미지 파일을 등록하세요." );
		return false;
	} else if ( $("#img2").val() == "" ) {
		alert( "두번째 상세이미지 파일을 등록하세요." );
		return false;
	} else if ( $("#img3").val() == "" ) {
		alert( "세번째 상세이미지 파일을 등록하세요." );
		return false;
	}
	return true;
}